<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            检测单关闭
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">检测单</div>
                    <div class="aui-list-item-input">
                        <input type="text" id="chkBillCode" disabled="true">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">检测结果</div>
                    <div class="aui-list-item-input">
                        <select id="chkResult">
                          <option value='0'>未判定</option>
                          <option value='1'>不合格</option>
                          <option value='5'>放行</option>
                          <option value='7'>合格</option>
                        </select>
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">备注</div>
                    <div class="aui-list-item-input">
                        <textarea id="remark"></textarea>
                    </div>
                </div>
            </li>
        </ul>
    </div>

    <div class='aui-btn aui-btn-info aui-btn-block' style="margin-top:10px;" onclick='save()'>保存</div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    //初始化查询仓库下拉框
    apiready = function() {

        $("#remark").val("");
        var chkBillCode = api.pageParam.chkBillCode;
        $("#chkBillCode").val(chkBillCode);

        //查询检测单判定结果
        doSearchChkBillChkResult();
    }


    //查询检测单明细项
    function doSearchChkBillChkResult() {

        //检测单号
        var chkBillCode = $("#chkBillCode").val();

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getChkBillChkResult";
        var data = {
            values: {
                chkBillCode: chkBillCode,
                un: un,
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    var chkResult = myobj.chkResult;

                    $("#chkResult").val(chkResult);

                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //保存
    function save() {
        //检测单号
        var chkBillCode = $("#chkBillCode").val();
        //检测结果
        var chkResult = $("#chkResult").val();
        //备注
        var remark = $("#remark").val();

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/chkBillSave";
        var data = {
            values: {
                chkBillCode: chkBillCode,
                chkResult: chkResult,
                remark: remark,
                un: un,
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    //返回主界面，刷新表格数据
                    api.closeWin();
                    var name = api.pageParam.name;
                    api.execScript({
                        name: name,
                        script: 'reset()'
                    });

                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>
